package cn.tedu.management.portal.util;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Accessors(chain = true)
public class R<T> implements Serializable {

    private Integer state;
    private String message;
    private T data;

    public static R ok(){
        return new R().setState(State.OK);
    }

    public static <T> R<T> ok(T data){
        return R.ok().setData(data);
    }

    public static R failure(Integer state, String message){
        return new R().setState(state).setMessage(message);
    }

    public static R failure(Integer state, Exception e){
        return new R().failure(state,e.getMessage());
    }

    public interface State{
        Integer OK=2000;
        Integer ERR_NOT_FOUND=4000;
        Integer ERR_NOT_A_MANAGER=4010;
        Integer ERR_INSERT=4020;

        //小川写的异常为 5 字号的
        Integer ERR_INVALID_PARAMETER=5000;
        Integer ERR_PHONE_DUPLICATE=5010;
        Integer ERR_DELETE=5020;
        Integer ERR_UPDATE=5030;

        //邓用的6号
        Integer ERR_EXITE_MESSAGE=6010;

    }
}
